﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AGrandVenture;
using System.Xml;
using System.IO;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate;


namespace DataEditor
{
    public static class GlobalFunctions
    {

        public static Stat LoadStat(string filename)
        {
            try
            {
                XmlReaderSettings settings = new XmlReaderSettings();

                settings.CloseInput = true;

                XmlReader reader = XmlReader.Create(new FileStream(filename, FileMode.Open), settings);

                Stat stat = IntermediateSerializer.Deserialize<Stat>(reader, null);

                reader.Close();

                return stat;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                return null;
            }
        }

        public static Race LoadRace(string filename)
        {
            try
            {
                XmlReaderSettings settings = new XmlReaderSettings();

                settings.CloseInput = true;

                XmlReader reader = XmlReader.Create(new FileStream(filename, FileMode.Open), settings);

                Race race = IntermediateSerializer.Deserialize<Race>(reader, null);

                reader.Close();

                return race;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                return null;
            }
        }
    }
}
